package de.koller.worlders.engine.entity.mo;

import de.koller.oceanFramework.tree.Child;
import de.koller.worlders.engine.entity.IAABB;
import de.koller.worlders.engine.util.Animation;
import de.koller.worlders.gameplay.IGameplayPlayerObject;
import de.koller.worlders.gameplay.PointRate;
import de.koller.worlders.render.VisualMap;

public class Player extends AbstractPlayer implements IGameplayPlayerObject {
	
	@Child public final PlayerSteeringC playerSteeringC = new PlayerSteeringC();
	
	@Child private final Animation animation = new Animation( 
			VisualMap.playerSWalk1, 
			VisualMap.playerSStand, 
			VisualMap.playerSWalk2
		);
	private final int[] walkSequence = new int[] { 1, 2, 1, 0 };
	private final int[] flySequence = new int[] { 0 };
	private final int[] standSequence = new int[] { 1 };
	
	public Player( float x, float y ) {
		super( x, y, 0.62f, 0.9f );
		this.getWalkSpeed().getValues().put( "default", 0.00495 );
		this.getJumpSpeed().getValues().put( "default", 0.00991 );
	}

	@Override
	protected void init() {
		super.init();

		animation.setTick( 150 );
		
		this.setVisual( VisualMap.playerSStand );
		this.mostate.setGameplayAffected( true );
		
		this.reset();
	}
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		wroot.getInput().setMouseGrab( false );
	}

	@Override
	public boolean walk( int a ) {
		if( !super.walk( a ) )
			return false;
		
		animation.setMy( this.getForce().getY() < 0 );
		
		if( this.isBottomContact() )
			animation.animateSequenze( walkSequence );
		else
			animation.animateSequenze( flySequence );
		
		if( a < 0 )
			animation.setMx( true );
		else if( a > 0 )
			animation.setMx( false );
		else if( a == 0 )
			animation.animateSequenze( standSequence );
		
		
		return true;
	}
	
	@Override
	public boolean jump() {
		if( !super.jump() )
			return false;
		
		wroot.gamePlayer.playerPoints.add( PointRate.Jump );
		return true;
	}

	@Override
	public IAABB getAABB() {
		return this;
	}

	@Override
	public float getScreenAngle() {
		return 0;
	}
	
}
